﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using CarParkBooking.DAL;

namespace CarParkBooking.Models
{
    public class CarParkBookingModel
    {
        public CarPark SelectedCarPark { get; set; }
        public int  RemainingSlotInMonth { get; set; }
        public DateTime SelectedMonth { get; set; }
        public IList<BookCalendarModel> BookCalendarModels { get; set; }
        public IList<string> ColorCodes { get; set; }
        public IList<CarPark> CarParks { get; set; }

        public static int GetRemaingBookSpacesOfUserInMonth(int selectedCarParkId, string userName, DateTime selectedMonth)
        {
            CarParkDataContext _dataContext = new CarParkDataContext();

            int numberOfBooked = _dataContext.Bookings.Where(b => b.UserName.Equals(userName)).Count();
            int maxSlotPerMonth = _dataContext.CarParks.Where(c => c.ID == selectedCarParkId).First().MaxSlotPerMonth.Value;

            return maxSlotPerMonth - numberOfBooked;
        }
    }
}